package com.cskaoyan.controller;

import com.cskaoyan.bean.Keyword;
import com.cskaoyan.service.KeywordService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.KeywordVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @ description:
 * - 关键词
 * - 显示,增加,修改,删除
 * @ author:台
 **/

//商场管理关键词
@RestController
public class KeywordController {

    @Autowired
    KeywordService keywordService;

    @RequestMapping("admin/keyword/list")
    public BaseRespVo keywordList(Integer page, Integer limit, String sort, String desc) {
        KeywordVo data = keywordService.keywordList(page, limit, sort, desc);
        BaseRespVo baseRespVo = BaseRespVo.ok(data);
        return baseRespVo;
    }

    @RequestMapping("admin/keyword/update")
    public BaseRespVo keywordUpdate(@RequestBody Keyword keyword) {
        Keyword data = keywordService.keywordUpdate(keyword);
        BaseRespVo baseRespVo = BaseRespVo.ok(data);
        return baseRespVo;
    }

    @RequestMapping("admin/keyword/create")
    public BaseRespVo keywordCreate(@RequestBody Keyword keyword) {
        Keyword keyword1 = new Keyword(null, keyword.getKeyword(), keyword.getUrl(), keyword.getIsHot(), keyword.getIsDefault(), null, new Date(), new Date(), false);
        Keyword data = keywordService.keywordCreate(keyword1);
        BaseRespVo baseRespVo = BaseRespVo.ok(data);
        return baseRespVo;
    }

    @RequestMapping("admin/keyword/delete")
    public BaseRespVo keywordDelete(@RequestBody Keyword keyword) {
        keywordService.keywordDelete(keyword);
        return BaseRespVo.ok();
    }
}
